package com.zbkj.service.service.mszs;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.zbkj.common.model.mszs.MszsRoomRecord;
import com.zbkj.common.request.PageParamRequest;
import com.zbkj.common.request.mszs.MszsRoomRecordRequest;
import com.zbkj.common.request.mszs.MszsRoomRecordSelectRequest;
import com.zbkj.common.response.mszs.MszsRoomRecordResponse;
import com.zbkj.service.dao.mszs.MszsRoomRecordDao;
import com.zbkj.service.service.mszs.MszsRoomRecordService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class MszsRoomRecordServiceImpl extends ServiceImpl<MszsRoomRecordDao, MszsRoomRecord> implements MszsRoomRecordService {

    @Resource
    private MszsRoomRecordDao recordDao;

    @Override
    public boolean insert(MszsRoomRecordRequest request) {
        MszsRoomRecord record=new MszsRoomRecord();
        BeanUtils.copyProperties(request, record);

        int ro = recordDao.insert(record);
        return ro > 0;
    }

    @Override
    public boolean update(MszsRoomRecordRequest request) {
        MszsRoomRecord record=new MszsRoomRecord();
        BeanUtils.copyProperties(request, record);

        int ro = recordDao.updateById(record);
        return ro > 0;
    }

    @Override
    public boolean delete(Integer id) {
        int ro = recordDao.deleteById(id);
        return ro > 0;
    }

    @Override
    public MszsRoomRecordResponse load(Integer id) {
        MszsRoomRecord record = recordDao.selectById(id);

        MszsRoomRecordResponse roomResponse=new MszsRoomRecordResponse();
        BeanUtils.copyProperties(record,roomResponse);
        return roomResponse;
    }

    @Override
    public List<MszsRoomRecord> pageList(MszsRoomRecordSelectRequest request, PageParamRequest pageParamRequest) {
        PageHelper.startPage(pageParamRequest.getPage(), pageParamRequest.getLimit());
        LambdaQueryWrapper<MszsRoomRecord> lambdaQueryWrapper = new LambdaQueryWrapper<>();

        lambdaQueryWrapper.eq(MszsRoomRecord::getJdId,request.getFjId());
        lambdaQueryWrapper.orderByDesc(MszsRoomRecord::getCreateTime);

        List<MszsRoomRecord> hotelList = recordDao.selectList(lambdaQueryWrapper);
        if (CollUtil.isEmpty(hotelList)) {
            return CollUtil.newArrayList();
        }
        return hotelList;
    }
}
